//
//  TJTransferDetailController.m
//  Teleport
//
//  Created by hc-101 on 2020/6/17.
//  Copyright © 2020 xtjun. All rights reserved.
//

#import "TJTransferDetailController.h"

@interface TJTransferDetailController ()

@property (strong, nonatomic) NSMutableArray *datas;

@property (assign, nonatomic) int type;

@end

@implementation TJTransferDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _datas = @[].mutableCopy;
    _type = [_dict[@"type"] intValue];
    
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 70)];
    headerView.backgroundColor = UIColor.whiteColor;
    UILabel *titleLabel = [UILabel lableWithSuperView:headerView font:MediumFont(24) color:UIColor_Hex(0x3882E8) title:@"" textAlignment:NSTextAlignmentLeft];
       [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
           make.centerY.offset(0);
           make.left.offset(16);
       }];
 
    self.navigationBar.lineView.hidden = YES;
    self.tableViewStyle = UITableViewStyleGrouped;
    self.tableView.rowHeight = 49;
    self.tableView.tableHeaderView = headerView;
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.showsHorizontalScrollIndicator = NO;
    self.tableView.backgroundColor = UIColor.whiteColor;
    self.tableView.contentInset = UIEdgeInsetsMake(0, 0, TabbarSafeBottomMargin, 0);
    [self.tableView registerClass:TJStyle1Cell.class forCellReuseIdentifier:style1Cell];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.offset(0);
        make.top.offset(KNavBarHight);
     }];
    
    
    if (_type == 0 || _type == 1) {
        
        titleLabel.text = [NSString stringWithFormat:@"%@%@", [self typeValue], _dict[@"num"]];
        [_datas addObject:[TJCellStyleModel cellStyleModelWithText:@"类型".localizedString detailText:[self typeValue] cellClass:@"TJStyle1Cell"]];
        [_datas addObject:[TJCellStyleModel cellStyleModelWithText:@"状态".localizedString detailText:[self stateValue] cellClass:@"TJStyle1Cell"]];
        [_datas addObject:[TJCellStyleModel cellStyleModelWithText:@"交易ID".localizedString detailText:_dict[@"orderNo"] cellClass:@"TJStyle1Cell"]];
        [_datas addObject:[TJCellStyleModel cellStyleModelWithText:@"交易hash".localizedString detailText:_dict[@"hash"] cellClass:@"TJStyle1Cell"]];
        [_datas addObject:[TJCellStyleModel cellStyleModelWithText:@"地址".localizedString detailText:_dict[@"other"] cellClass:@"TJStyle1Cell"]];
        [_datas addObject:[TJCellStyleModel cellStyleModelWithText:@"时间".localizedString detailText:_dict[@"time"] cellClass:@"TJStyle1Cell"]];
        
        
        UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 60)];
        UIButton *cancelButton = [UIButton buttonWithSuperView:footerView font:UIFont_Px(16) color:UIColor.whiteColor title:@"取消提币".localizedString];
        cancelButton.backgroundColor = UIColor.tj_mainColor;
        [cancelButton shearRoundedCornersWithRadiu:3];
        [cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.offset(-16);
            make.left.offset(16);
            make.height.offset(44);
            make.center.offset(0);
        }];
        
        self.tableView.tableFooterView = footerView;
        
    } else if (_type == 2 || _type == 3 || _type == 6 || _type == 7) {
        
        titleLabel.text = [NSString stringWithFormat:@"%@%@%@", _type == 2 ? @"+" : @"-", _dict[@"num"], [_coinNo intValue] == 1 ? @"BTC" : @"USDT"];
        [_datas addObject:[TJCellStyleModel cellStyleModelWithText:@"类型".localizedString detailText:[self typeValue] cellClass:@"TJStyle1Cell"]];
        [_datas addObject:[TJCellStyleModel cellStyleModelWithText:@"状态".localizedString detailText:[self stateValue] cellClass:@"TJStyle1Cell"]];
        [_datas addObject:[TJCellStyleModel cellStyleModelWithText:@"UID" detailText:_dict[@"orderNo"] cellClass:@"TJStyle1Cell"]];
        [_datas addObject:[TJCellStyleModel cellStyleModelWithText:@"时间".localizedString detailText:_dict[@"time"] cellClass:@"TJStyle1Cell"]];
                
    }
    

    
    
}


- (NSString *)stateValue {
    int type = [_dict[@"state"] intValue];
    if (type == 0) return @"审核中".localizedString;
    if (type == 1) return @"已成功".localizedString;
    if (type == 2) return @"审核失败".localizedString;
    return @"";
}

- (NSString *)typeValue {
    int type = [_dict[@"type"] intValue];
    if (type == 0) return @"提币".localizedString;
    if (type == 1) return @"充币".localizedString;
    if (type == 2) return @"转入".localizedString;
    if (type == 3) return @"转出".localizedString;
    if (type == 4) return @"购买".localizedString;
    if (type == 5) return @"出售".localizedString;
    if (type == 6) return @"系统加币".localizedString;
    if (type == 7) return @"系统减币".localizedString;
    return @"";
}


 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.datas.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    TJStyle1Cell *cell = [tableView dequeueReusableCellWithIdentifier:style1Cell forIndexPath:indexPath];
    TJCellStyleModel *model = self.datas[indexPath.row];
    cell.model = model;
    cell.tj_textLabel.textColor = UIColor_Hex(0x656565);
    cell.tj_textLabel.font = UIFont_Px(15);
    cell.selectionStyle = model.isNeedCopy ? UITableViewCellSelectionStyleDefault : UITableViewCellSelectionStyleNone;
    cell.tj_detailTextLabel.font = UIFont_Px(15);
    cell.tj_detailTextLabel.textColor = UIColor_Hex(0x262626);
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    TJCellStyleModel *model = self.datas[indexPath.row];
    
    if (model.isNeedCopy) {
        [Tools copyStringToPasteboard:model.detailText.replacingEmptyString];
        return;
    }
    
}

 
- (void)loadData {
    
    
    NSMutableDictionary *parameters = @{
        @"transferId": _dict[@"orderNo"],
        @"token": TJUserInfo.readInfo.token
    }.mutableCopy;
    
    [TJNetworking.shareNetworking POST:@"tradeInfo/getTradeList" parameters:parameters success:^(NSDictionary * _Nonnull responseObject, NSDictionary *data) {
        
     
 
 
    } failure:^(NSError * _Nonnull error) {
        self.displayEmpty = YES;
         [self.tableView reloadData];
    }];

}



@end
